import { SET_UPLOAD_ATTRIBUTE } from '../constant';

export const setFileUploadAttribute = (data) => ({ type: SET_UPLOAD_ATTRIBUTE, data })

export const setPartFileUploadAttribute = (data) => (dispatch, getState) => {
  // 获取原始值
  let key = Object.keys(data)[0]
  let value = data[key]
  let originData = getState().fileUploadAttribute
  let storeValue = originData[key] || {}
  originData[key] = Object.assign(storeValue, value)
  dispatch(setFileUploadAttribute(Object.assign({}, originData)))
}

export const removeFileByIndex = (key) => (dispatch, getState) => {
  let originData = getState().fileUploadAttribute
  delete originData[key]
  dispatch(setFileUploadAttribute(Object.assign({}, originData)))
}

